﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using System.Web.UI.HtmlControls;
using Model;
using System.Data;

namespace WebLosgic.Carress
{
    public partial class CarrierManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getBind();
            }
        }

        protected void getBind()
        {
            int pageIndex = AspNetPagerTool.CurrentPageIndex;
            int pagesize = AspNetPagerTool.PageSize;
            int count = 0;
            CarriessCyBLL cel = new CarriessCyBLL();
            Carriers car = new Carriers();
            car.CarriesID = TxtnUber.Text;
            car.LeaverDate = TxtCarrierDate.Text;
            car.zhiDate = TxtCarrierDate2.Text;
            car.SendLinkman = TxtFaPeople.Text;
            car.ReceiveLinkman = TxtdetailPeople.Text;
            RptBindDrive.DataSource=cel.readCarrierBind(pageIndex,pagesize,out count,car);
            AspNetPagerTool.RecordCount = count;
            RptBindDrive.DataBind();
        }

        
        ///承运单状态   
        public string findstateBInd(string state)
        {
            string str = "";
            switch (state)
            {
                case ("0"):
                    str = "待调度";
                    break;
                case ("1"):
                    str = "已调度";
                    break;
                case ("2"):
                    str = "已签收";
                    break;
                case ("3"):
                    str = "已结算";
                    break;
                default:
                    state="0";
                    break;
            }
            return str;
        }

        protected void Btnsel_Click(object sender, EventArgs e)
        {
            getBind();
        }

        protected void LinkButdel_Click(object sender, EventArgs e)
        {
            int carrieID =Convert.ToInt32(((LinkButton)sender).CommandArgument);
            CarriessCyBLL cybl = new CarriessCyBLL();
            string str = cybl.DelCarrider(carrieID);
            if(str== "删除成功！")
            {
                string name = Session["names"].ToString();
                string Behavor = "" + name + ": 删除承运单信息";
                int TypeId = 15;
                int UserID = Convert.ToInt32(Session["UserIDs"]);
                string Parameters = @"" + carrieID + "";
                string ProcName = "p_delCarr";
                HttpRequest request = HttpContext.Current.Request;
                string IP = "192.168.0.1";
                int IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('" + str + "')", true);
            }
            else
            {
                string name = Session["names"].ToString();
                string Behavor = "" + name + ": 删除承运单信息";
                int TypeId = 15;
                int UserID = Convert.ToInt32(Session["UserIDs"]);
                string Parameters = @"" + carrieID;
                string ProcName = "p_delCarr";
                HttpRequest request = HttpContext.Current.Request;
                string IP = "192.168.0.1";
                int IsExcePion = 1;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('" + str + "')", true);
            }
            getBind();
        }

        protected void LinkButupda_Click(object sender, EventArgs e)
        {
            int carrieID = Convert.ToInt32(((LinkButton)sender).CommandArgument);
            Response.Redirect("UpdateCarrier.aspx?ID="+carrieID);
        }

        protected void RptBindDrive_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if(e.CommandName== "Deail")
            {
                int carrieID =Convert.ToInt32(e.CommandArgument);
                Response.Redirect("Carriesdetails.aspx?ID=" + carrieID);
            }
        }

        protected void LinkBtnInsert_Click(object sender, EventArgs e)
        {
            int carrid = Convert.ToInt32(((LinkButton)sender).CommandArgument);
            Response.Redirect("InsertCargo.aspx?CID="+carrid);
        }

        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            getBind();
        }
    }
}